package com.book.lizhi.ui.fragment;

import android.support.v4.app.Fragment;
import android.text.TextUtils;

import com.book.lizhi.AppApplication;
import com.book.lizhi.http.AppRequest;
import com.book.lizhi.http.FakeX509TrustManager;
import com.book.lizhi.http.OnHttpListener;
import com.book.lizhi.util.AppLog;

public class BaseFragment extends Fragment {
	public static BaseFragment newInstance(int sectionNumber) {

		if (AppApplication.instance.isCheck) {
			sectionNumber++;
		}

		switch (sectionNumber) {
		case 0:
			return new BookshelfFragment();
		case 1:
			return new StoryFragment();
		case 2:
			return new SongFragment();
		case 3:
			return new FilmFragment();
		case 4:
			return new GasStationFragment();
		default:
			return null;
		}

	}

	public void sendGetRequest(String url, OnHttpListener listener) {
		AppLog.e(url);
		if (listener != null) {
			listener.onHttpStart();
			String response = AppApplication.instance.jsonCache.getJsonStr(url);
			if (!TextUtils.isEmpty(response)) {
				listener.onResponse(true,url, response);
				return;
			}
		}
		FakeX509TrustManager.allowAllSSL();
		AppRequest request = new AppRequest(url, listener);
		AppApplication.instance.requestQueue.add(request);
	}

}
